import { CoreEntity } from "GameLoop/WorldState/EntityManager/Entitys";
import { ActionBase, ActionBaseOfCreep } from "../ActionBase";

 
/**
 * 发送资源。只有当资源就绪或者终端满了情况才会发送
 */
export class ActionSend  extends ActionBase<IActionCMD<"send">>
{
    public execute(action: IActionCMD<"send">): ActionCode 
    {
        const room = action.arg.entity;
        const coreentity = room.getEntity("CoreEntity") as Required<CoreEntity>;
        const arg  = action.arg;
        if(!coreentity.Terminal)
        {
            return 0;
        }
     
        // 3.发送资源.分为两种情况发送能量 和发送非能量
        /**
             * 1.计算终端空闲空间
             * 2.计算终端需要填充的资源。
             *      如果终端放得下。则填充.
             *      如果放不下。则计算本次填充的数量
            */
        // 
        const freespace = coreentity.Terminal.store.getFreeCapacity();
        const existAmountOfResource = coreentity.Terminal.store.getUsedCapacity(arg.Resource.resourceType);
        const existAmountOfEnergy = coreentity.Terminal.store.getUsedCapacity(RESOURCE_ENERGY);
        const transfer_cost = Game.market.calcTransactionCost(arg.Resource.amount,arg.From,arg.To); // 路费需要的数量

        // 需要的总空闲空间
        const space_need = transfer_cost+(arg.Resource.amount-existAmountOfResource);

        if(space_need<=freespace)
        {
            // 终端能够放得下
            // 1.填充资源
            // 2.填充路费
            
        }
        else
        {
            // 
        }

        return 0;
    }
}